Skip to content

block PeerName register requests#13887

Merged
acpana merged 9 commits intomainfrom
acpana/nonuser-peering-reg-2
Jul 29, 2022
Merged

block PeerName register requests#13887
acpana merged 9 commits intomainfrom
acpana/nonuser-peering-reg-2

Conversation

@acpana
Copy link
Copy Markdown
Contributor

@acpana acpana commented Jul 25, 2022

Signed-off-by: acpana 8968914+acpana@users.noreply.github.com

description

We probably want to block the Catalog.Register endpoint from taking in requests with any PeerName (on nodes, services, checks).

proposal

The approach taken here is to add a config value that is non user configurable. But our test agent/servers can turn it on.

Signed-off-by: acpana <8968914+acpana@users.noreply.github.com>
@acpana acpana added pr/no-changelog PR does not need a corresponding .changelog entry theme/cluster-peering Related to Consul's cluster peering feature labels Jul 25, 2022
@github-actions github-actions bot added the theme/config Relating to Consul Agent configuration, including reloading label Jul 25, 2022

portsConfig := randomPortsSource(t, a.UseTLS)

//a.Overrides = `
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could turn this on for all agents but I'd recommend turning it off by default and just enabling it for the tests that need it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not having this is the cause of all the existing CI failures. However if you uncomment this then your new tests regarding checking the enforcement behavior of not allowing the PeerName field to be set would then fail.

I generally agree that the best course of action would be to update tests that do the nasty things to opt into the behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as of now, all tests that need this config option on have it so I should remove this commented block

Copy link
Copy Markdown
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the need to for the new config to bypass the restriction in the case of tests. However, it makes me think we have gotten the interfaces and boundaries between components wrong if we need to do this.

Do you know how many/which tests get broken if we just unconditionally restrict this? I think there are a few different ways tests should inject peered services.

  1. Within the agent/consul package those tests can insert directly into the state store or they can call raftApply on the server directly.
  2. Outside of agent/consul unit tests should use mocks that don't require real data injection (or an actual server)
  3. Outside of agent/consul integration tests should set up multiple agents and let the peering replication stream get the data injected instead of doing it directly.

With that approach, we shouldn't need any configurability of allowing/disallowing setting the peer name through the RPC endpoint.

I realize that we may have too many tests to make that feasible for this PR which is why I would be curious which/how many tests it breaks to just always enforce the restriction.

"github.com/hashicorp/consul/testrpc"
)

func TestCatalogRegister_DenyPeeringRegistration(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the functionality changed is within agent/consul/catalog_endpoint.go, the unit test should live in agent/consul/catalog_endpoint_test.go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I wanted to test turning off the setting at the agent level but also add more cases at the consul level; what do you think of the current approach?

acpana added 2 commits July 28, 2022 15:00
Signed-off-by: acpana <8968914+acpana@users.noreply.github.com>
Signed-off-by: acpana <8968914+acpana@users.noreply.github.com>
@acpana acpana changed the title wip block PeerName register requests block PeerName register requests Jul 28, 2022
@acpana acpana marked this pull request as ready for review July 28, 2022 23:01
@acpana acpana requested a review from mkeeler July 28, 2022 23:01
Copy link
Copy Markdown
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a quick peak at the CI failures and they look legit. Mostly due to not being able to register services with peer names.

acpana added 4 commits July 29, 2022 11:57
Signed-off-by: acpana <8968914+acpana@users.noreply.github.com>
Signed-off-by: acpana <8968914+acpana@users.noreply.github.com>
Signed-off-by: acpana <8968914+acpana@users.noreply.github.com>
Signed-off-by: acpana <8968914+acpana@users.noreply.github.com>
@acpana
Copy link
Copy Markdown
Contributor Author

acpana commented Jul 29, 2022

We discussed internally and we DO NOT WANT to include this change in 1.13; this change will go out in 1.13.1 or later. No backport labels should be applied.

acpana added 2 commits July 29, 2022 12:40
Signed-off-by: acpana <8968914+acpana@users.noreply.github.com>
Signed-off-by: acpana <8968914+acpana@users.noreply.github.com>
@acpana acpana requested review from kisunji and mkeeler July 29, 2022 19:46
@acpana acpana merged commit a45bb1f into main Jul 29, 2022
@acpana acpana deleted the acpana/nonuser-peering-reg-2 branch July 29, 2022 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/no-changelog PR does not need a corresponding .changelog entry theme/cluster-peering Related to Consul's cluster peering feature theme/config Relating to Consul Agent configuration, including reloading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants